//创建电脑AI用户
/**
 * @param	r_room	AI待加入的房间
 * @param	r_chip	AI带入的筹码
 * @param	
 */
var AIUser = function(r_room, r_chip ) {
	this._user = null;
	//电脑名字
	this._name = "100";
	//电脑带入筹码
	this._chip = r_chip;
	//待加入房间
	this._room = r_room;
	//AI服务器
	this._AIHost = { ip:'localhost', port:80 };
	//创建用户
	this.creatUser = function() {
		var _host = new java.net.InetSocketAddress(this._AIHost.ip, this._AIHost.port);		
		var _channel = new java.nio.channels.SocketChannel.open(_host);
		//trace(_channel.socket().getInetAddress().getHostAddress());
		//this._user = new Packages.it.gotoandplay.smartfoxserver.data.User(_channel, this._name, _zone.getName());
		var _result = _server.loginUser(this._name, '', _channel, true);		
		if (_result.success) {
			this._user = _server.getUserByChannel(_channel);
		}
		var _param = { };
		_param['chip'] = 10000;
		_param['state'] = 0;
		//一定得保证userId与用户名字相同，否则坐下无反应
		_param['userId'] = 100;
		_param['face'] = '0.gif';
		_param['level'] = 100;
		_param['name'] = "簡單電腦";
		_param["label"] = 12;
		setUserVars(this._user, _param);
	}
	//进入房间
	this.joinRoom = function() {
		var _param = { };
		_param['rid'] = this._room.getId();
		_roomAc.joinRoom( -1, this._user, _param);		
	}
	
	//带入筹码坐下
	this.sitDown = function() {
		//查找可用座位	
		var _sit;
		for (var _i = 1; _i < 10; _i++ ) {
			if (this._room.getUserByPlayerIndex(_i) == null) {
				_sit = _i;
				break;
			}
		}
		var _param = { sit:_sit, chip:this._chip };		
		_roomAc.sitDown(this._room, this._user, _param);
	}	
	this.creatUser();
	this.joinRoom();
	this.sitDown();
	return this._user;
}
